﻿<?php
include_once('dao_log.php');
include_once('dao_bo_session.php');
class Request_Filter
{

	 public $curr_request=null;
	 public $request_allow='*';
	 public $ip_allow='-'; 
	 public $is_allow=null;
	 public $name="-";
	 
	public function Request_Filter($cfg)
	{
		global $request_filter_cfg;
		$this->ip_allow = $cfg['ip_allow'];
		$this->request_allow = $cfg['request_allow'];
	}
	 public function check()
	{
		
		if(isset( $this->is_allow)&&strlen($this->curr_request)>0)
		{
			return $this->is_allow;
		}
		//-----------------------------------
		//检查request
		$is_req_allow=false;
		$this->curr_request =bo_session_get('request');
		if($this->request_allow==('*'))
		{
			$is_req_allow = true;
		}
		else  if(strlen($this->request_allow)&&strlen($this->curr_request))
		{
			if(strpos($this->request_allow,$this->curr_request)===false)
			{
				$is_req_allow = false;
			}
			else
			{
				$is_req_allow = true;
			}
		}
		//-----------------------------------
		//检查ip
		$client_ip = get_client_ip();	
		$is_ip_allow =false;	
		if($this->ip_allow=="*")
		{
			$is_ip_allow=true;
		}
		else if(strlen($this->ip_allow))
		{
			if(strpos($this->ip_allow,$client_ip)===false)
			{
				$is_ip_allow = false;
			}
			else
			{
				$is_ip_allow = true;
			}
		}
		$this->is_allow = $is_ip_allow&&$is_req_allow;
		return $this->is_allow;
	}
};

foreach ($request_filter_cfg as $key=>$value)
{
	DAO_Log::add_filter_allow($key,new request_filter($value));
}
?>